package com.market.controller.wx;

import com.market.bean.MarketUser;
import com.market.bean.common.BasePageInfo;
import com.market.bean.common.BaseRespVo;
import com.market.bean.common.CommonData;
import com.market.bean.vo.wx.WxFootprintListVo;
import com.market.service.wx.WxFootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author:WalterChan
 * @Decription:WxFootprintController
 * @Date Created in 2023-01-02-12:08
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {

    @Autowired
    WxFootprintService wxFootprintService;


    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info){
        Subject subject = SecurityUtils.getSubject();
        MarketUser primaryPrincipal = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId=primaryPrincipal.getId();
//        等待整合Subject，先设置传入的用户id=4
//        Integer userId=4;
        CommonData<WxFootprintListVo> data=wxFootprintService.list(info,userId);
        return BaseRespVo.ok(data);

    }
//
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map<String,String> map){
        Subject subject = SecurityUtils.getSubject();
        MarketUser primaryPrincipal = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId=primaryPrincipal.getId();

        String id = map.get("id");
        wxFootprintService.delete(Integer.valueOf(id),userId);
        return BaseRespVo.ok();

    }
}
